<template>
  <el-dialog title="分配角色" :visible="isShow" @close="closeEvent">
    <el-checkbox-group v-model="roleArr">
      <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>
    <template #footer>
      <div style="text-align: center">
        <el-button type="primary" @click="submit">提交</el-button>
        <el-button @click="closeEvent">取消</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script>
import { sysrole } from '@/api/setting'
import { sysUser } from '@/api/user'
import { sysUserAssignRoles } from '@/api/employees.js'
export default {
  name: '',
  model: {
    prop: 'isShow'
  },
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      id: '',
      roleArr: [],
      list: []
    }
  },
  computed: {},
  created() {
    this.getData()
  },
  methods: {
    // 获取所有角色列表
    async getData() {
      const res = await sysrole({
        page: 1,
        pagesize: 100
      })
      this.list = res.data.rows
    },
    // 获取角色基本信息
    async getUserInfo(id) {
      const res = await sysUser(id)
      this.roleArr = res.data.roleIds
      this.id = id
      console.log(res, 369)
    },
    // 给员工分配角色
    async submit() {
      await sysUserAssignRoles(this.id, this.roleArr)
      this.$message.success('分配角色成功')
      this.closeEvent()
    },
    closeEvent() {
      this.$emit('input', false)
      // this.$emit('close')
      this.roleArr = []
    }
  }
}
</script>
<style lang="less" scoped></style>
